package demo1;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何华树
 * Date: 2024-07-10
 * Time: 10:29
 */

public class main {
    public static void swap(int[] array,int i,int j) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
    public static void func1(int[] array) {
        int left = 0;
        int right = array.length -1;
        while(left < right) {
            if(left < right && array[left] % 2 != 0){
                left++;
            }
            if(left < right && array[right] % 2 == 0) {
                right--;
            }
            swap(array,left,right);
        }
    }

    public static int[] func2(int[] array,int find) {
        int[] arr = new int[2];
        for (int i = 0; i < array.length; i++) {
            for(int j = i+1;j<array.length;j++){
                if(array[i] + array[j] == find){
                    arr[0] = i;
                    arr[1] = j;
                }
            }
        }
        return arr;
    }
    public static int func3(int[] array) {
        int a = 0;
        for(int i = 0; i<array.length;i++) {
            a ^= array[i];
        }
        return a;
    }
    public static int func4(int[] array) {
        Arrays.sort(array);
        int a = array[array.length/2];
        return a;
    }
    public static boolean func5(int[] array) {
        int count = 0;
        for(int i = 0 ;i<array.length;i++) {
            if(array[i] % 2 != 0) {
                count++;
                if(count == 3){
                    return true;
                }
            }else{
                count = 0;
            }
        }
        return false;
    }
    public static void main1(String[] args) {
//        int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9};
//        func1(array);
//        System.out.println(Arrays.toString(array));
        //找出两个元素的下标
//        int[] array = new int[]{2,7,5,6,9};
//        int ret[] = func2(array,12);
//        System.out.println(Arrays.toString(ret));
        //单身狗问题
//        int[] array ={1,2,2,1,3};
//        int ret = func3(array);
//        System.out.println(ret);
        //多数问题
//        int[] array = new int[]{1,2,1,2,1,2,2};
//        int ret = func4(array);
//        System.out.println(ret);
        //判断连续三个奇数
        int[] array = {1,2,4,5,8,6,7,10,5};
        boolean a = func5(array);
        System.out.println(a);
    }

    public static void main(String[] args) {
        //数组的打印方法
        int[][] arr = {{1,2,3},{4,5,6}};
        //循环打印
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println("========================");
        int[][] arr1 = new int[][]{{1,2,3},{4,5,6}};
        //for each 循环打印
        for(int[] array : arr1){
            for (int x: array) {
                System.out.print(x+" ");
            }
            System.out.println();
        }
        System.out.println("========================");

        //使用数组包的工具
//        System.out.println(Arrays.toString(arr));//打印一维数组
        System.out.println(Arrays.deepToString(arr));//打印二维数组的

        int[][] arr2 = new int[2][3];

        int[][] arr3 = new int[2][];
    }
}
